package com.ruoyi.system.api.dept;

import com.ruoyi.common.core.core.domain.R;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.system.api.dept.dto.DeptRespDTO;
import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.service.ISysDeptService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
public class DeptApiImpl implements DeptApi {
    @Resource
    private ISysDeptService sysDeptService;

    @Override
    public R<DeptRespDTO> getDept(Long id) {
        SysDept dept = sysDeptService.getById(id);
        return R.ok(BeanUtils.toBean(dept, DeptRespDTO.class));
    }

    @Override
    public R<List<DeptRespDTO>> getDeptList(Collection<Long> ids) {
        List<SysDept> depts = sysDeptService.listByIds(ids);
        return R.ok(BeanUtils.toBean(depts, DeptRespDTO.class));
    }

    @Override
    public R<Boolean> validateDeptList(Collection<Long> ids) {
        sysDeptService.validateDeptList(ids);
        return R.ok(true);
    }

    @Override
    public R<List<DeptRespDTO>> getChildDeptList(Long id) {
        List<SysDept> depts = sysDeptService.getChildDeptList(id);
        return R.ok(BeanUtils.toBean(depts, DeptRespDTO.class));
    }
}
